import { computed, defineProps } from 'vue'

/**
 * 弹窗的主要emit事件
 * **/
export const emitBaseEventList = (['update:visible', 'dialogConfirmEvent', 'dialogCloseEvent'])

/**
 * 弹窗组件基础数据，需要在组件中设置props和emit，并将其当做参数传进来
 * @param props dialog的props参数，主要用到了props.visible
 * @param emit dialog的emit参数，主要用到了emit('update:visible')和emit('dialogCloseEvent')
 * **/
export const useDialogCommonData = (props, emit) => {
  const dialogVisible = computed({
    get: () => props.visible,
    set: (v) => {
      emit('update:visible', v)
    }
  })

  // 关闭弹窗事件
  const handleClose = () => {
    dialogVisible.value = false
    emit('dialogCloseEvent')
  }

  return {
    dialogVisible,
    handleClose
  }
}
